package com.igeek.handler;

import com.alibaba.fastjson.JSON;
import com.igeek.entity.Employee;
import com.igeek.json.JsonResult;
import com.igeek.service.EmpService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("emp")
public class EmployeeHandler {
    @Resource
    private EmpService empService;

    @GetMapping("all/{depId}")
    public JsonResult findByDep(@PathVariable("depId") int depId){
        JsonResult jsonResult = new JsonResult();
        //查询部门的员工信息
        List<Employee> list = empService.findByDepId(depId);
        if(!list.isEmpty()){
            jsonResult.setHttpCode(200);
            jsonResult.setData(list);
        }
        else{
            jsonResult.setHttpCode(500);
        }
        return jsonResult;
    }

    @PutMapping("salary/{empId}/{salary}")
    public JsonResult modifySalary(@PathVariable("empId") int empId,@PathVariable("salary") double salary){
        System.out.println(empId+","+salary);
        JsonResult jsonResult = new JsonResult();
        Employee employee = new Employee();
        employee.setEmpId(empId);
        employee.setSalary(salary);
        empService.update(employee);
        jsonResult.setData(employee);
        return jsonResult;
    }
}
